﻿using lib472;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace libedi
{
   public class DataBaseFactory
    {
        public DataBaseFactory(string server, string user, int port, string passwod,string cbsdata, string code, string edi, string tabinf, string xmlsetcontent, string catk)
        {
            this.CBSDATA = cbsdata;
            this.CODE = code;
            this.EDI = edi;
            this.XMLSETCONTENT = xmlsetcontent;
            this.TABINF = tabinf;
            this.CATK = catk;
            this.SERVER = server;
            this.USER = user;
            this.PORT = port;
            this.PASSWORD = passwod;
        }
        public string CBSDATA { get; }

        public string CODE { get; }

        public string EDI { get; }

        public string TABINF { get; }

        public string XMLSETCONTENT { get; }

        public string CATK { get; }

        public string SERVER { get; }

        public string USER { get; }

        public int PORT { get; }
        public string PASSWORD { get; }

        public string GetConnectionString(SourceType databaseType)
        {
            string database = string.Empty;
            
            switch (databaseType)
            {
                case SourceType.CBSDATA:
                {
                        database = CBSDATA;
                        break;
                    }
                case SourceType.EDI:
                    {
                        database = EDI;
                        break;
                    }
                case SourceType.CODE:
                    {
                        database = CODE;
                        break;
                    }
                case SourceType.XmlSetContent:
                    {
                        database = XMLSETCONTENT;
                        break;
                    }
                case SourceType.TableInf:
                    {
                        database = TABINF;
                        break;
                    }
                case SourceType.Catk:
                    {
                        database = CATK;
                        break;
                    }
            }

            string ConnectionString = $"Server={SERVER};Port={PORT};Database={database};User={USER};Password={PASSWORD};Allow User Variables=true;AllowLoadLocalInfile=true";
            return ConnectionString;
        }

        public string GetConnectionString(string database)
        {
            string ConnectionString = $"Server={SERVER};Port={PORT};Database={database};User={USER};Password={PASSWORD};Allow User Variables=true;AllowLoadLocalInfile=true";
            return ConnectionString;
        }
    }
}
